package leetcode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0491.java
 * @Author : WangRuoyu
 * @Date 2023/11/2 22:08
 */


public class Q0491 {
    int[] nums;
    List<Integer> tmp = new ArrayList<>();
    List<List<Integer>> res = new ArrayList<>();

    public void dfs(int k) {
        if (tmp.size() > 1) {
            res.add(new ArrayList<>(tmp));
        }
        HashSet<Integer> set = new HashSet<Integer>();
        for (int i = k; i < nums.length; i++) {
            if (set.contains(nums[i])) {
                continue;
            }
            if (tmp.isEmpty() || tmp.get(tmp.size() - 1) <= nums[i]) {
                set.add(nums[i]);
                tmp.add(nums[i]);
                dfs(i + 1);
                tmp.remove(tmp.size() - 1);
            }
        }
    }

    public List<List<Integer>> findSubsequences(int[] nums) {
        this.nums = nums;
        dfs(0);
        return res;
    }

    public static void main(String[] args) {
        Q0491 sl = new Q0491();
        int[] nums = {1, 1, 1, 1};
        System.out.println(sl.findSubsequences(nums));
    }
}